package sy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import sy.pageModel.DataGrid;
import sy.pageModel.Json;
import sy.pageModel.PageHelper;
import sy.pageModel.TransportDetail;
import sy.service.TransportDetailServiceI;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;


/**
 * transportDetail控制器
 * 
 * @author lichenhao
 * 
 */
@Controller
@RequestMapping("/transportDetailController")
public class TransportDetailController extends BaseController {

	@Autowired
	private TransportDetailServiceI transportDetailService;
	
	


	@RequestMapping("/transportDetail")
	@ResponseBody
	public DataGrid transportDetail(String id, PageHelper ph) {
		return transportDetailService.transportDetail(id);
	}
	
	/**
	 * 跳转到添加明细信息页面
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/addPage")
	public String addPage(HttpServletRequest request ,String id) {
		TransportDetail transportDetail = new TransportDetail();
		transportDetail.setTransportId(id);
		
		request.setAttribute("transportDetail", transportDetail);
		return "/business/transportDetailAdd";
	}

	/**
	 * 添加外协人员
	 * 
	 * @return
	 */
	@RequestMapping("/add")
	@ResponseBody
	public Json add(TransportDetail transportDetail) {
		Json j = new Json();
		try {
			transportDetailService.add(transportDetail);
			j.setSuccess(true);
			j.setMsg("添加成功！");
			j.setObj(transportDetail);
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		return j;
	}

	/**
	 * 跳转到外协人员修改页面
	 * 
	 * @return
	 */
	@RequestMapping("/transportDetailEdit")
	public String transportDetailEdit(HttpServletRequest request, String id) {
		TransportDetail transportDetail = transportDetailService.get(id);
		request.setAttribute("transportDetail", transportDetail);
		return "/business/transportDetailEdit";
	}

	@RequestMapping("/transportDBDetailEdit")
	public String transportDBDetailEdit(HttpServletRequest request, String id) {
		TransportDetail transportDetail = transportDetailService.get(id);
		request.setAttribute("transportDetail", transportDetail);
		return "/business/transportDBDetailEdit";
	}


	@RequestMapping("/edit")
	@ResponseBody
	public Json edit(TransportDetail transportDetail) {
		Json j = new Json();
		try {
			transportDetailService.edit(transportDetail);
			j.setSuccess(true);
			j.setMsg("编辑成功！");
			j.setObj(transportDetail);
		} catch (Exception e) {
			// e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/delete")
	@ResponseBody
	public Json delete(String id, HttpSession session) {
		Json j = new Json();
		transportDetailService.delete(id);
		j.setMsg("删除成功！");
		j.setSuccess(true);
		return j;
	}


	@RequestMapping("/productCombogrid")
	@ResponseBody
	public DataGrid productCombogrid(String q, PageHelper ph) {
		return transportDetailService.productCombogrid(q, ph);
	}

}
